#include "message.hpp"

int main()
{
    // qiangsir::BaseMessage::ptr bmp = qiangsir::BaseMessageFactory::create(qiangsir::MType::REQ_RPC);
    // qiangsir::RpcRequest::ptr rrp = std::dynamic_pointer_cast<qiangsir::RpcRequest>(bmp);

    // Json::Value param;
    // param["num1"] = 11;
    // param["num2"] = 22;
    // rrp->setMethod("Add");
    // rrp->setParams(param);
    // std::string body = rrp->serialize();
    // std::cout<<body<<std::endl;

    // qiangsir::BaseMessage::ptr bmp2 = qiangsir::BaseMessageFactory::create(qiangsir::MType::REQ_RPC);
    // qiangsir::RpcRequest::ptr rrp2 = std::dynamic_pointer_cast<qiangsir::RpcRequest>(bmp2);

    // Json::Value root;

    // bool ret = rrp2->deSerialize(body);
    // if(ret == false) std::cout<<"falid1\n";
    // if(rrp2->check() == false)  std::cout<<"falid2\n";

    // std::cout<<rrp2->method()<<std::endl;
    // std::cout<<rrp2->params()["num1"]<<std::endl;
    // std::cout<<rrp2->params()["num2"]<<std::endl;

    // qiangsir::BaseMessage::ptr bmp = qiangsir::BaseMessageFactory::create(qiangsir::MType::REQ_TOPIC);
    // qiangsir::TopicRequest::ptr trp = std::dynamic_pointer_cast<qiangsir::TopicRequest>(bmp);

    // trp->setTopicKey("News");
    // trp->setOptype(qiangsir::TopicOptype::TOPIC_PUBLISH);
    // trp->setMessage("大家好");

    // std::string body = trp->serialize();
    // std::cout<<body<<std::endl;

    // qiangsir::BaseMessage::ptr bmp2 = qiangsir::BaseMessageFactory::create(qiangsir::MType::REQ_TOPIC);
    // qiangsir::TopicRequest::ptr trp2 = std::dynamic_pointer_cast<qiangsir::TopicRequest>(bmp2);

    // Json::Value root;
    // bool ret = trp2->deSerialize(body);
    // if(ret == false) std::cout<<"faild1\n";
    // if(trp2->check() == false) std::cout<<"faild2\n";

    // std::cout<<trp2->topicKey()<<std::endl;
    // std::cout<<trp2->topicMessage()<<std::endl;

    // qiangsir::BaseMessage::ptr bmp = qiangsir::BaseMessageFactory::create(qiangsir::MType::REQ_SERVERICE);
    // qiangsir::ServerRequest::ptr trp = std::dynamic_pointer_cast<qiangsir::ServerRequest>(bmp);

    // trp->setMethod("Add");
    // trp->setOptype(qiangsir::ServiceOptype::SERVICE_DISCOVERY);

    // std::string body = trp->serialize();
    // std::cout<<body<<std::endl;

    // qiangsir::BaseMessage::ptr bmp2 = qiangsir::BaseMessageFactory::create(qiangsir::MType::REQ_SERVERICE);
    // qiangsir::ServerRequest::ptr trp2 = std::dynamic_pointer_cast<qiangsir::ServerRequest>(bmp2);

    // Json::Value root;
    // bool ret = trp2->deSerialize(body);
    // if(ret == false) std::cout<<"faild1\n";
    // if(trp2->check() == false) std::cout<<"faild2\n";

    // std::cout<<trp2->method()<<std::endl;
    // std::cout<<(int)trp2->optype()<<std::endl;

    //     qiangsir::BaseMessage::ptr bmp = qiangsir::BaseMessageFactory::create(qiangsir::MType::RSP_RPC);
    //     qiangsir::RpcResponse::ptr trp = std::dynamic_pointer_cast<qiangsir::RpcResponse>(bmp);

    //     trp->setRcode(qiangsir::RCode::RCODE_OK);
    //     trp->setResult(33);

    //     std::string body = trp->serialize();
    //     std::cout << body << std::endl;

    //    qiangsir::BaseMessage::ptr bmp2 = qiangsir::BaseMessageFactory::create(qiangsir::MType::RSP_RPC);
    //     qiangsir::RpcResponse::ptr trp2 = std::dynamic_pointer_cast<qiangsir::RpcResponse>(bmp2);

    //     Json::Value root;
    //     bool ret = trp2->deSerialize(body);
    //     if (ret == false)
    //         std::cout << "faild1\n";
    //     if (trp2->check() == false)
    //         std::cout << "faild2\n";

    //     std::cout << (int)trp2->rcode() << std::endl;
    //     std::cout << trp2->result() << std::endl;

    qiangsir::BaseMessage::ptr bmp = qiangsir::BaseMessageFactory::create(qiangsir::MType::RSP_SERVERICE);
    qiangsir::ServerResponse::ptr trp = std::dynamic_pointer_cast<qiangsir::ServerResponse>(bmp);

    trp->setRcode(qiangsir::RCode::RCODE_OK);
    trp->setMethod("faxian");
    trp->setOptype(qiangsir::ServiceOptype::SERVICE_DISCOVERY);
    std::vector<qiangsir::Address> addrs;
    addrs.push_back({"121321323", 22});
    addrs.push_back({"121321323", 23});
    addrs.push_back({"121321323", 24});
    trp->setHost(addrs);

    std::string body = trp->serialize();
    std::cout << body << std::endl;

    qiangsir::BaseMessage::ptr bmp2 = qiangsir::BaseMessageFactory::create(qiangsir::MType::RSP_SERVERICE);
    qiangsir::ServerResponse::ptr trp2 = std::dynamic_pointer_cast<qiangsir::ServerResponse>(bmp2);

    Json::Value root;
    bool ret = trp2->deSerialize(body);
    if (ret == false)
        std::cout << "faild1\n";
    if (trp2->check() == false)
        std::cout << "faild2\n";

    std::cout << (int)trp2->rcode() << std::endl;
    std::cout << (int)trp2->optype() << std::endl;
    std::cout << trp2->method() << std::endl;
    std::vector<qiangsir::Address> addrss = trp2->host();
    for (auto addr : addrss)
    {
        std::cout << addr.first << ":" << addr.second << std::endl;
    }

    return 0;
}